<template>
	<view>
		<view class="title" v-if="libraryDetail">{{libraryDetail.name}}</view>
		<view class="address">{{libraryDetail.address}}</view>
		<view class="status">
			<view class="businessStatus">
				<view v-if="libraryDetail.businessState === '1'">营业中</view>
				<view v-else>暂停营业</view>
			</view>
			<view class="businessHours">{{libraryDetail.businessHours}}</view>
		</view>
		<view class="img">
			<image :src="libraryDetail.imgUrl" mode=""></image>
		</view>
		<view class="content">
			{{libraryDetail.description}}
		</view>
		<view class="comment" @click="gotopage(libraryDetail.id)">
			<uni-icons type="chat" size="30"></uni-icons>
			<view>评论</view>
		</view>
	</view>
</template>

<script>
	import {
		digitalList
	} from '../../../api/library'

	import libraryData from "@/common/librarydata.js";

	export default {
		data() {
			return {
				libraryDetail: {}
			}
		},
		onLoad(options) {
			const id = options.id; // 从URL中获取id参数 
			this.getLibraryDetail(id)
		},
		methods: {
			gotopage(id) {
				uni.navigateTo({
					url: `/pages/library/commentList/commentList?id=${id}`
				})
			},
			async getLibraryDetail(id) {
				const token = uni.getStorageSync('token');
				if (!token) {
					throw new Error('没有有效的token');
				}

				const headers = {
					"Authorization": token
				};

				let res = await digitalList({
					id,
					headers
				})
				// console.log(res);
				if (res.code === 200) {
					this.libraryDetail = res.data;
				} else {
					this.libraryDetail = libraryData.libraryDetail.data
				}

			}
		}
	}
</script>

<style scoped>
	.title {
		font-size: 20px;
		text-align: center;
		line-height: 2;
	}

	.address {
		font-size: 16px;
		text-align: center;
		line-height: 2;
	}

	.status {
		font-size: 18px;
		padding: 0 30px;
		line-height: 2;
		display: flex;
		justify-content: space-around;
	}

	.img {
		height: 260px;
		padding: 0 30rpx;
		margin: 20px 0;
	}

	.img image {
		width: 100%;
		height: 100%;
	}

	.businessStatus {
		color: red;
	}

	.content {
		padding: 0 30rpx;
		font-size: 18px;
		line-height: 1.6;
		text-indent: 2em;
	}

	.comment {
		padding: 20px 0;
		text-align: center;
		font-size: 18px;
	}
</style>